package com.jr.controller;

import com.jr.entry.BlogText;
import com.jr.service.TopListService;
import com.jr.util.ResultObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;

@RestController /*替换@RestController=@Controller + @ResponseBody*/
@RequestMapping("/Top/")
public class TopListController {
    @Autowired
    private TopListService topListMapperService;
    @Autowired
    private ResultObject result;
    @RequestMapping("showTop")
/*    public ResultObject showTop(TopListAndBlogText topListAndBlogText){
        result.setStatus(400);
        int i = blogTextMapperService.showAllBlogText().size();
        ArrayList<BlogText> blogTextArrayList = new ArrayList<>();
        for (int j=0;j<i;j++){
            BlogText blogText = blogTextMapperService.showAllBlogText().get(j);
            blogTextArrayList.add(blogText);
        }
        return blogTextArrayList;
    }*/
    public ArrayList<BlogText> showTop(BlogText blogText){
        result.setStatus(400);
        int i = topListMapperService.showTop(blogText).size();
        ArrayList<BlogText> blogTextArrayList = new ArrayList<>();
        for (int j=0;j<i;j++){
            BlogText blogText1 = topListMapperService.showTop(blogText).get(j);
            blogTextArrayList.add(blogText1);
        }
        System.out.println(blogTextArrayList);
        return blogTextArrayList;
    }

    @RequestMapping("showType")
    public ResultObject showTypeById(Integer tid){
        result.setStatus(100);
        result.setResult(topListMapperService.selectTypeById(tid));
        return result;
    }
}
